﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MyLib.MyBase.MyWeb;
using MyChocCuoi.Setting;
using MyLoad.LoadStatic;
using System.Data;
using MyChocCuoi.DB.Content;
using MyLib.MyUtility;
namespace MyLoad.LoadContent
{

    public class LDetail: MyLoadWeb
    {
        int NewsID = 0;

       public NewsObject mNewsObj = new NewsObject();

        string TemplatePathVideo = "~/Templates/Content/DetailVideo.html";
        public LDetail(MyASHX CurrentPage)
        {
            this.CurrentPage = CurrentPage;
            TemplatePath = "~/Templates/Content/Detail.html";
            Init();
        }
      
      
        // Hàm trả về chuỗi có chứa mã HTML
        protected override string BuildHTML()
        {
            try
            {
                if (CurrentPage.Request.QueryString["nid"] != null)
                    int.TryParse(CurrentPage.Request.QueryString["nid"], out NewsID);

                if (NewsID <= 0)
                    return string.Empty;

                News mNews = new News();

                DataTable mTable = mNews.Select(2, NewsID.ToString(), ((int)News.Status.Active).ToString());

                if (mTable.Rows.Count < 1)
                    return string.Empty;

                mNewsObj = NewsObject.Convert(mTable);

                LoadMember.LMemberBox mMemberBox = new LoadMember.LMemberBox(CurrentPage, mNewsObj.MemberID);

                if (mNewsObj.TypeID == (int)News.NewsType.Video)
                {
                    string[] arr = { mNewsObj.Title, mNewsObj.DetailLink(),
                                   MyConvert.DateTime2Text(mNewsObj.CreateDate), 
                                   mNewsObj.ViewCount.ToString(), mNewsObj.Embed, mMemberBox.GetHTML() };

                    return LoadTemplateByArray(TemplatePathVideo, arr);
                }
                else
                {
                    string[] arr = { mNewsObj.Title, mNewsObj.DetailLink(),
                                   MyConvert.DateTime2Text(mNewsObj.CreateDate), 
                                   mNewsObj.ViewCount.ToString(), mNewsObj.Image, mMemberBox.GetHTML() };
                    return LoadTemplateByArray(TemplatePath, arr);
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
